package easy.id_0_100;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class hua13 {
    public static void main(String[] args) {
        String[] s={"5",
                "2019-01-01 00:00:00.004",
                "2019-01-01 00:00:00.004",
                "2019-01-01 00:00:01.006",
                "2019-01-01 00:00:01.006",
                "2019-01-01 00:00:01.005"};
        String[] s2={"6",
                "2019-01-01 00:00:00.001",
                "2019-01-01 00:00:00.002",
                "2019-01-01 00:00:00.003",
                "2019-01-01 08:59:00.123",
                "2019-01-01 08:59:00.123",
                "2018-12-28 13:08:00.999"};
        System.out.println(freeOrder(s));
    }

    // 待实现函数，在此函数中填入答题代码
    private static int freeOrder(String[] orderTime) {
        Map<String,Integer> map=new HashMap<>();
        int result=0;
        for(int i=0;i<orderTime.length;i++){
            String[] times=parseOrder(orderTime[i]);
            if(!map.containsKey(times[0])){
                map.put(times[0],Integer.parseInt(times[1]));
            }else{
                if(Integer.parseInt(times[1])<map.get(times[0])){
                    map.put(times[0],Integer.parseInt(times[1]));
                }
            }
        }
        System.out.println("所有的ordertime：");
        for(String time :orderTime){
            System.out.println(time);
        }
        System.out.println("map：");
        for (String key : map.keySet()) {
            Integer value = map.get(key);
            System.out.println("Key: " + key + ", Value: " + value);
        }
        String[] times2 =parseOrder(orderTime[2]);
        System.out.println(orderTime[2]);
        System.out.println("-");
        System.out.println(map.get(times2[0]));
        System.out.println(Integer.parseInt(times2[1]));
        System.out.println(map.get(times2[0]) == Integer.parseInt(times2[1]));

        for(int i=0;i<orderTime.length;i++){
            String[] times=parseOrder(orderTime[i]);
            if(map.containsKey(times[0]) && map.get(times[0])==Integer.parseInt(times[1])){

                result++;
            }
        }
        return result;
    }
    private static String[] parseOrder(String ordertime){
        String year_sec=ordertime.substring(0,19);
//        System.out.println(year_sec);
//        String year = ordertime.substring(0, 4);
//        String month = ordertime.substring(5, 5+2);
//        String day = ordertime.substring(8, 8+2);
//        String hours = ordertime.substring(11, 11+2);
//        String min = ordertime.substring(14, 14+2);
//        String sec = ordertime.substring(17, 17+2);
        String msec = ordertime.substring(20, 20+3);
//        System.out.println(year);
//        System.out.println(month);
//        System.out.println(day);;
//        System.out.println(hours);
//        System.out.println(min);
//        System.out.println(sec);
//        System.out.println(msec);
        String[] re=new String[2];
        re[0]=year_sec;
        re[1]=msec;
        return re;
    }

}
